package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCodingRuleSegment;
import com.ruoyi.system.service.ISysCodingRuleSegmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 编码规则段配置Controller
 * 
 * @author ruoyi
 * @date 2025-08-08
 */
@RestController
@RequestMapping("/system/segment")
public class SysCodingRuleSegmentController extends BaseController
{
    @Autowired
    private ISysCodingRuleSegmentService sysCodingRuleSegmentService;

    /**
     * 查询编码规则段配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:segment:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCodingRuleSegment sysCodingRuleSegment)
    {
        startPage();
        List<SysCodingRuleSegment> list = sysCodingRuleSegmentService.selectSysCodingRuleSegmentList(sysCodingRuleSegment);
        return getDataTable(list);
    }

    /**
     * 导出编码规则段配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:segment:export')")
    @Log(title = "编码规则段配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCodingRuleSegment sysCodingRuleSegment)
    {
        List<SysCodingRuleSegment> list = sysCodingRuleSegmentService.selectSysCodingRuleSegmentList(sysCodingRuleSegment);
        ExcelUtil<SysCodingRuleSegment> util = new ExcelUtil<SysCodingRuleSegment>(SysCodingRuleSegment.class);
        util.exportExcel(response, list, "编码规则段配置数据");
    }

    /**
     * 获取编码规则段配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:segment:query')")
    @GetMapping(value = "/{segmentId}")
    public AjaxResult getInfo(@PathVariable("segmentId") Long segmentId)
    {
        return success(sysCodingRuleSegmentService.selectSysCodingRuleSegmentBySegmentId(segmentId));
    }

    /**
     * 新增编码规则段配置
     */
    @PreAuthorize("@ss.hasPermi('system:segment:add')")
    @Log(title = "编码规则段配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCodingRuleSegment sysCodingRuleSegment)
    {
        return toAjax(sysCodingRuleSegmentService.insertSysCodingRuleSegment(sysCodingRuleSegment));
    }

    /**
     * 修改编码规则段配置
     */
    @PreAuthorize("@ss.hasPermi('system:segment:edit')")
    @Log(title = "编码规则段配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCodingRuleSegment sysCodingRuleSegment)
    {
        return toAjax(sysCodingRuleSegmentService.updateSysCodingRuleSegment(sysCodingRuleSegment));
    }

    /**
     * 删除编码规则段配置
     */
    @PreAuthorize("@ss.hasPermi('system:segment:remove')")
    @Log(title = "编码规则段配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{segmentIds}")
    public AjaxResult remove(@PathVariable Long[] segmentIds)
    {
        return toAjax(sysCodingRuleSegmentService.deleteSysCodingRuleSegmentBySegmentIds(segmentIds));
    }
}
